package org.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.dao.IDataDao;
import org.entity.ConsigneeInfo;
import org.entity.ConsignorInfo;
import org.entity.OrderInfo;
import org.entity.SrCity;
import org.util.SqlUtil;

public class DataDaoImpl implements IDataDao {
	
	public boolean addData(ConsigneeInfo consigneeInfo,
						ConsignorInfo consignorInfo,
						OrderInfo orderInfo,
						SrCity srCity)
	{
		String sql = "insert into consigneeinfo values("+consigneeInfo.getConsigneeid()+",'"+consigneeInfo.getConsigneename()+"',"+consigneeInfo.getPhone()+",'"+consigneeInfo.getConsigneeaddress()+"')";
		String sql1 = "insert into consignorinfo values("+consignorInfo.getConsignorid()+",'"+consignorInfo.getConsignorname()+"',"+consignorInfo.getPhone()+",'"+consignorInfo.getConsignoraddress()+"')";
		String sql2 = "insert into orderInfo values("+orderInfo.getOrderid()+","+orderInfo.getGoodswt()+","+orderInfo.getMailfee()+",'"+orderInfo.getConsignorid()+"','"+orderInfo.getConsigneeid()+"')";
		String sql3 = "insert into srCity values("+srCity.getOrderid()+",'"+srCity.getSendaddress()+"','"+srCity.getReachaddress()+"')";
		
		SqlUtil su=new SqlUtil();
		int i1 = su.updateUtil(sql);
		int i2 = su.updateUtil(sql1);
		int i3 = su.updateUtil(sql2);
		int i4 = su.updateUtil(sql3);
		if(i1>0&&i2>0&&i3>0&&i4>0){
			return true;
		}else{
			return false;
		}
	}
	
	public int queryOrderId(){
		int flag=10000;
		SqlUtil su=new SqlUtil();
		String sql="select orderid from srcity order by orderid desc";
		ResultSet rs = su.queryUtil(sql);
		try {
				if(rs.next()){
					flag=Integer.parseInt(rs.getString(1))+1;
				}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}
	@Override
	public int addMyOrder(int id, String userName) {
		String sql="insert into MyOrder values("+id+",'"+userName+"')";
		SqlUtil su=new SqlUtil();
		int i = su.updateUtil(sql);
		return i;
	}

}
